home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / util / st / part01 / serial.a < prev    next >
Text File  |  1990-06-04  |  6KB  |  334 lines

  1. ; Serial.a
  2. ; created by John Schultz, 17-Sep-89
  3. ; last modified 17-April-90
  4.  
  5.     section    Serial,CODE
  6.  
  7.     xref    _raw
  8.  
  9.     xdef    _baudper
  10.     xdef    _openserial
  11.     xdef    _closeserial
  12.     xdef    _sendser
  13.     xdef    _readser
  14.     xdef    _checkser
  15.     xdef    _rawtoascii
  16.     xdef    _sendsernobuff
  17.  
  18.  
  19. _LVOSetIntVector equ    $FFFFFF5E
  20.  
  21. ESCAPE        equ    69        ; input-handler rawkey code
  22.  
  23. CLOCK        equ    3579545
  24. _baudper    dc.w     (CLOCK/19200)-1    ; defaualt
  25.  
  26. CUSTOM        equ    $dff000
  27. SERDATR        equ    $000018
  28. SERDAT        equ    $000030
  29. SERPER        equ    $000032
  30.  
  31. INTENA        equ    $00009a
  32. INTENAR        equ    $00001c
  33. INTREQ        equ    $00009c
  34.  
  35. TBEQSIZE    equ    128        ; buffer size in bytes,
  36. RBFQSIZE    equ    128        ; increase or decrease as needed
  37.  
  38. LED        equ    $bfe001        ; toggle power led, audio filter
  39.  
  40. ledroll        dc.b    %00010001    ; flash every 4 bytes
  41. ledpad        dc.b    0
  42.  
  43. oldintena    dc.w    0
  44.  
  45. tbequeue    ds.b    TBEQSIZE    ; circular queue
  46. tbeqend
  47. tbehead        dc.l    tbequeue
  48. tbetail       dc.l    tbequeue
  49.  
  50. oldtbeinterrupt    dc.l    0
  51. oldrbfinterrupt    dc.l    0
  52.  
  53. tbeinterrupt
  54.     dc.l    0    ; ln_succ
  55.     dc.l    0    ; ln_prec
  56.     dc.b    2    ; NT_INTERRUPT
  57.     dc.b    127    ; ln_pri
  58.     dc.l    0    ; ln_name
  59.     dc.l    tbehead    ; is_data
  60.     dc.l    tbehandler ; is_code
  61.  
  62. rbfinterrupt
  63.     dc.l    0    ; ln_succ
  64.     dc.l    0    ; ln_prec
  65.     dc.b    2    ; NT_INTERRUPT
  66.     dc.b    127    ; ln_pri
  67.     dc.l    0    ; ln_name
  68.     dc.l    rbftail    ; is_data
  69.     dc.l    rbfhandler ; is_code
  70.  
  71.  
  72. tbehandler    
  73.     move.w    #1,INTREQ(a0)        ; clear TBE interrupt
  74.     move.l    (a1),a1            ; a1 = tbehead, (a1) = pointer
  75.     cmp.l    tbetail,a1        ; now a1 = pointer
  76.     beq.b    99$
  77.     move.w    SERDATR(a0),d0        ; check to make sure emtpy
  78.     btst    #13,d0
  79.     beq.b    99$
  80.     move.w    #$100,d0
  81.     move.b    (a1)+,d0        ; get byte from queue
  82.     move.w    d0,SERDAT(a0)        ; send byte
  83.     cmpa.l    #tbeqend,a1
  84.     bne.b    10$
  85.     lea    tbequeue(pc),a1
  86. 10$    move.l    a1,tbehead
  87. 99$
  88.     rts
  89.  
  90. rbfqueue    ds.b    RBFQSIZE
  91. rbfqend    
  92. rbfhead        dc.l    rbfqueue
  93. rbftail        dc.l    rbfqueue
  94.  
  95. rbfhandler
  96.     move.w    SERDATR(a0),d0        ; a0 = custom
  97.     move.w    #$800,INTREQ(a0)    ; clear RBF interrupt
  98.     move.l    (a1),a0            ; a1 = rbftail, get pointer
  99.     move.b    d0,(a0)+        ; write byte to buffer
  100.     cmpa.l    #rbfqend,a0
  101.     bne.b    10$
  102.     lea    rbfqueue(pc),a0
  103. 10$    move.l    a0,(a1)            ; a1 = rbftail
  104.  
  105. ;99$
  106. ;    move.b    ledroll(pc),d0        ; remove from 99$-100$ for more
  107. ;    rol.b    #1,d0            ; speed
  108. ;    move.b    d0,ledroll
  109. ;    btst    #1,d0
  110. ;    beq.b    100$
  111. ;    bchg.b    #1,LED            ; toggle power led / audio filter
  112. ;100$
  113.     rts
  114.  
  115. _openserial
  116.     move.l    a6,-(sp)
  117.     lea    CUSTOM,a0
  118.     move.w    #$4000,INTENA(a0)    ; disable
  119.     move.l    $4,a6            ; execbase
  120.     lea    rbfinterrupt(pc),a1
  121.     moveq.l    #11,d0
  122.     jsr    _LVOSetIntVector(a6)
  123.     move.l    d0,oldrbfinterrupt
  124.     lea    tbeinterrupt(pc),a1
  125.     moveq.l    #0,d0
  126.     jsr    _LVOSetIntVector(a6)
  127.     move.l    d0,oldtbeinterrupt
  128.  
  129.     lea    CUSTOM,a0
  130.     move.w    _baudper,SERPER(a0)    ; set period
  131.  
  132.     move.w    #$3fff,$bfd0fe        ; init handshake lines
  133.     move.w    INTENAR(a0),oldintena
  134.     move.w    #$8801,INTENA(a0)    ; turn on RBF and TBE INTENA
  135.     move.w    #$0801,INTREQ(a0)    ; clear RBF and TBE INTREQ
  136.     move.w    #$c000,INTENA(a0)    ; enable
  137.     move.l    (sp)+,a6
  138.     rts
  139.  
  140.  
  141. _closeserial
  142.     move.l    a6,-(sp)
  143.     lea    CUSTOM,a0
  144.     move.w    #$4000,INTENA(a0)    ; disable
  145.     move.l    $4,a6            ; execbase
  146.     move.l    oldrbfinterrupt,a1
  147.     moveq.l    #11,d0
  148.     jsr    _LVOSetIntVector(a6)
  149.     move.l    oldtbeinterrupt,a1
  150.     moveq.l    #0,d0
  151.     jsr    _LVOSetIntVector(a6)
  152.  
  153.     lea    CUSTOM,a0
  154.     move.w    #$0801,INTENA(a0)    ; turn off RBF and TBE INTENA
  155.     move.w    oldintena,d0
  156.     and.w    #$0801,d0        ; mask for bit 11 and bit 1.
  157.     bset    #15,d0            ; set/clr = 1 (set)
  158.     move.w    d0,INTENA(a0)         ; reset old RBF and TBE INTENA
  159.  
  160.     bclr.b    #1,LED
  161.  
  162.     move.w    #$0801,INTREQ(a0)    ; clear RBF and TBE INTREQ
  163.     move.w    #$c000,INTENA(a0)    ; enable
  164.     move.l    (sp)+,a6
  165.     rts
  166.  
  167. _sendser
  168.     lea    CUSTOM,a0
  169.     move.w    #$4000,INTENA(a0)
  170.  
  171.     move.l    tbetail,a1
  172.     cmpa.l    tbehead,a1
  173.     beq.b    5$
  174.     move.w    #$8001,INTREQ(a0)    ; generate a tbe interrupt
  175. 5$
  176.     move.b    d0,(a1)+        ; queue up byte
  177.     cmpa.l    #tbeqend,a1
  178.     bne.b    10$
  179.     lea    tbequeue(pc),a1
  180. 10$    move.l    a1,tbetail
  181.     
  182.     move.w    #$c000,INTENA(a0)
  183.     rts
  184.  
  185.  
  186. ; send byte in d0 to serial port, non-buffered.
  187. _sendsernobuff
  188.     lea    CUSTOM,a0
  189.     move.w    #$4000,INTENA(a0)
  190. 1$    move.w    SERDATR,d1
  191.     btst    #13,d1            ; check TBE
  192.     beq.b    1$            ; buffer busy
  193.     
  194.     move.w    #$100,d1
  195.     move.b    d0,d1
  196.     move.w    d1,SERDAT(a0)
  197. 2$    move.w    SERDATR(a0),d1
  198.     btst    #13,d1            ; check TBE
  199.     beq.b    2$            ; buffer busy
  200.     move.w    #$001,INTREQ(a0)    ; clear TBE interrupt
  201.  
  202.     move.w    #$c000,INTENA(a0)
  203.     rts
  204.  
  205.  
  206. ; uses a0
  207. _readser
  208.     cmp.w    #ESCAPE,_raw    ; quits on ESC from input handler
  209.     beq.b    20$
  210.     move.l    rbfhead,a0
  211.     cmpa.l    rbftail,a0
  212.     beq.b    _readser
  213.     move.b    (a0)+,d0
  214.     cmpa.l    #rbfqend,a0
  215.     bne.b    10$
  216.     lea    rbfqueue(pc),a0
  217. 10$    move.l    a0,rbfhead
  218. 20$
  219.     rts
  220.  
  221. _checkser
  222.     move.l    rbfhead,a0
  223.     cmpa.l    rbftail,a0
  224.     bne.b    dataisin
  225.     moveq.l    #0,d0
  226.     rts
  227. dataisin
  228.     moveq.l    #1,d0
  229.     rts
  230.  
  231.  
  232. ; rawkey in d0
  233. ; ascii returned in d0
  234. _rawtoascii
  235.     cmp.b    #79,d0
  236.     bls.b    getascii    
  237.     moveq.l    #0,d0
  238.     rts
  239. getascii
  240.     lea    asciitable,a0
  241.     move.b    0(a0,d0),d0
  242.     rts
  243.  
  244.  
  245.     section    asciitable,data
  246.  
  247. ; This is a quick trick, don't do this for anything other than
  248. ; home use, boys and girls.  Use rawkeyconvert, etc.
  249.  
  250. asciitable
  251.     dc.b    '`'    ; backquote `
  252.     dc.b    '1'
  253.     dc.b    '2'
  254.     dc.b    '3'
  255.     dc.b    '4'
  256.     dc.b    '5'
  257.     dc.b    '6'
  258.     dc.b    '7'
  259.     dc.b    '8'
  260.     dc.b    '9'
  261.     dc.b    '0'
  262.     dc.b    '-'
  263.     dc.b    '='
  264.     dc.b    $0D    ; \
  265.     dc.b    0
  266.     dc.b    '0'    ; keypad 0
  267.     dc.b    'q'
  268.     dc.b    'w'
  269.     dc.b    'e'
  270.     dc.b    'r'
  271.     dc.b    't'
  272.     dc.b    'y'
  273.     dc.b    'u'
  274.     dc.b    'i'
  275.     dc.b    'o'
  276.     dc.b    'p'
  277.     dc.b    '['
  278.     dc.b    ']'
  279.     dc.b    0
  280.     dc.b    '1'
  281.     dc.b    '2'
  282.     dc.b    '3'
  283.     dc.b    'a'
  284.     dc.b    's'
  285.     dc.b    'd'
  286.     dc.b    'f'
  287.     dc.b    'g'
  288.     dc.b    'h'
  289.     dc.b    'j'
  290.     dc.b    'k'
  291.     dc.b    'l'
  292.     dc.b    ';'
  293.     dc.b    $27    ; ' single quote
  294.     dc.b    0
  295.     dc.b    0
  296.     dc.b    '4'
  297.     dc.b    '5'
  298.     dc.b    '6'
  299.     dc.b    0
  300.     dc.b    'z'
  301.     dc.b    'x'
  302.     dc.b    'c'
  303.     dc.b    'v'
  304.     dc.b    'b'
  305.     dc.b    'n'
  306.     dc.b    'm'
  307.     dc.b    ','
  308.     dc.b    '.'
  309.     dc.b    '/'
  310.     dc.b    0
  311.     dc.b    '.'    ; keypad
  312.     dc.b    '7'
  313.     dc.b    '8'
  314.     dc.b    '9'
  315.     dc.b    ' '
  316.     dc.b    $8    ; backspace
  317.     dc.b    $9    ; tab
  318.     dc.b    $D    ; enter  cr
  319.     dc.b    $D    ; return cr
  320.     dc.b    $1B    ; ESC
  321.     dc.b    $7f    ; delete
  322.     dc.b    ''
  323.     dc.b    0
  324.     dc.b    0
  325.     dc.b    '-'    ; keypad
  326.     dc.b    0
  327.     dc.b    0    
  328.     dc.b    $b    ; up arrow
  329.     dc.b    $a    ; down arrow
  330.     dc.b    $20    ; rt arrow
  331.     dc.b    $8    ; left arrow
  332.     
  333.     END
  334.